﻿# CMakeList.txt: 顶层 CMake 项目文件，在此处执行全局配置
# 并包含子项目。
#
cmake_minimum_required (VERSION 3.8 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_BUILD_TYPE "Debug")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")

    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -Wall -g2 -ggdb -ldl -pthread")
    set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -Wall -g2 -ggdb -ldl -pthread")

else()
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O3 -Wall -ldl -pthread")
    set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -O3 -Wall -ldl -pthread")
endif()
add_definitions(-D _FILE_OFFSET_BITS=64)

project ("GitStore")
set(PROJECT_BINARY_DIR "/home/luqin2/Code/fork-store/build")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)

if(UNIX)
    if(X86_64 OR CMAKE_SIZEOF_VOID_P EQUAL 8)
        message("x86_64 machine")
        if(EXISTS /lib64)
            list(APPEND CMAKE_LIBRARY_PATH /lib64)
        else()
            list(APPEND CMAKE_LIBRARY_PATH /lib)
        endif()
        if(EXISTS /usr/lib64)
            list(APPEND CMAKE_LIBRARY_PATH /usr/lib64)
            list(APPEND CMAKE_LIBRARY_PATH /usr/local/lib64)
            list(APPEND CMAKE_LIBRARY_PATH /usr/lib64/x86_64-linux-gnu)
        else()
            list(APPEND CMAKE_LIBRARY_PATH /usr/lib)
            list(APPEND CMAKE_LIBRARY_PATH /usr/local/lib)
            list(APPEND CMAKE_LIBRARY_PATH /usr/lib/x86_64-linux-gnu)
        endif()
    elseif(X86 OR CMAKE_SIZEOF_VOID_P EQUAL 4)
        message("x86 machine")
        if(EXISTS /lib32)
            list(APPEND CMAKE_LIBRARY_PATH /lib32)
        else()
            list(APPEND CMAKE_LIBRARY_PATH /lib)
        endif()
        if(EXISTS /usr/lib32)
            list(APPEND CMAKE_LIBRARY_PATH /usr/lib32)
            list(APPEND CMAKE_LIBRARY_PATH /usr/local/lib32)
            list(APPEND CMAKE_LIBRARY_PATH /usr/lib32/x86-linux-gnu)
        else()
            list(APPEND CMAKE_LIBRARY_PATH /usr/lib)
            list(APPEND CMAKE_LIBRARY_PATH /usr/local/lib)
            list(APPEND CMAKE_LIBRARY_PATH /usr/lib/x86-linux-gnu)
        endif()
    endif()
else()
    message("Not Support in Windows Platform!")
endif()

list(APPEND CMAKE_INCLUDE_PATH /usr/include)
list(APPEND CMAKE_INCLUDE_PATH /usr/local/include)

# 包含子项目。
add_subdirectory ("GitStoreMeta")
add_subdirectory ("GitStoreGrpcLib")
add_subdirectory ("GitStoreGrpcService")
add_subdirectory ("GitStoreGrpcClient")
add_subdirectory ("GitStoreRestService")

